home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / multimedia / tuxpaint / tuxpaint-0.9.20-win32-installer.exe / {app} / docs / zh_tw / mkTuxpaintIM.py < prev    next >
Text File  |  2008-07-01  |  2KB  |  47 lines

  1. #!/usr/bin/env python
  2. # -*- coding: Big5 -*-
  3. # Copyright: Song Huang <songhuang.tw@gmail.com>
  4. # create: 2007/11/04
  5. # License: GNU GPL 
  6. ver = "0.1"
  7.  
  8. from optparse import OptionParser
  9. from codecs import open as copen
  10.  
  11. if __name__ == '__main__':
  12.     # parse script arguments
  13.     optparser = OptionParser(usage='./%prog [options]', version="%prog "+ver)
  14.     optparser.add_option("-o", "--outputfile",   action="store",  
  15.                          help=unicode("┐ΘÑX└╔«╫¬║ªW║┘","big5"))
  16.     optparser.add_option("-m", "--phonemap",   action="store",
  17.                          help=unicode("ñññσ╗P¬`¡╡╣∩╖╙¬φ(utf8 - expect file was xcin table:phone.cin)","big5"))
  18.     (options, args) = optparser.parse_args()
  19.  
  20.     ## │]⌐wÑD¡n┼▄╝╞
  21.     #  ┐ΘÑX└╔ªW
  22.     outfile = copen(options.outputfile, "w", "utf8")
  23.     outfile.write("section\n\n")
  24.     # ñññσ╗P¬`¡╡╣∩╖╙¬φ
  25.     phonemap = options.phonemap
  26.  
  27.     # ░⌡ªµ┐ΘÑX
  28.     cinfile = copen(phonemap, "r", "utf8")
  29.     (bopomofo, chinachar) = cinfile.readline().split()
  30.     bpmf_count = 0
  31.     bpmf_temp = bopomofo
  32.     while bopomofo:
  33.         if bpmf_temp == bopomofo:
  34.             bpmf_count += 1
  35.         else:
  36.             bpmf_count = 1
  37.         bpmf_temp  = bopomofo
  38.         chinacharnum = str(hex(ord(chinachar)))[2:]
  39.         outfile.write("%s\t%s%s\t-\t# %s \n" % (chinacharnum, bopomofo, bpmf_count, chinachar))
  40.     try:
  41.             (bopomofo, chinachar) = cinfile.readline().split()
  42.     except:
  43.             break
  44.     # ╡▓º⌠
  45.     cinfile.close()
  46.     outfile.close()
  47.